<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
             label-width="98px">
      <el-form-item label="供应商名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入供应商名称"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <!--<el-form-item label="税号" prop="taxNo">
          <el-input v-model="queryParams.taxNo" placeholder="请输入税号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="地址" prop="addr">
          <el-input v-model="queryParams.addr" placeholder="请输入地址"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="电话" prop="tel">
          <el-input v-model="queryParams.tel" placeholder="请输入电话"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>-->
      <el-form-item label="开户行" prop="bankName">
        <el-input v-model="queryParams.bankName" placeholder="请输入开户行"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <!--<el-form-item label="银行账号" prop="bankNo">
          <el-input v-model="queryParams.bankNo" placeholder="请输入银行账号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="备注信息" prop="info">
          <el-input v-model="queryParams.info" placeholder="请输入备注信息"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange"
              :max-height="tableMaxHeight">
      <el-table-column label="序号" align="center" type="index"/>
      <el-table-column label="供应商名称" align="center" prop="name" width="300"/>
      <el-table-column label="开户行" align="center" prop="bankName"/>
      <el-table-column label="账号" align="center" prop="bankNo"/>
      <el-table-column label="备注信息" align="center" prop="remark"/>
      <el-table-column label="账户余额" align="center" prop="balanceMoney"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-document"
                     @click="handleBalanceList(scope.row)" v-hasPermi="['develop:GoodsSupplier:edit']">收支详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"/>

    <goodsSupplier-form ref="form" @ok="getList"></goodsSupplier-form>
    <pay-supplier-balance-list-module ref="balanceListModule" @ok="getList"></pay-supplier-balance-list-module>

    <upload-dialog ref="uploadDialog" @ok="getList" @handleFileSuccess="handleFileSuccess"></upload-dialog>
  </div>
</template>

<script>
import {deleteAction, getAction} from '@/api/manage'
import GoodsSupplierForm from '@/views/develop/goodsSupplier/module/GoodsSupplierForm'
import UploadDialog from "@/views/upload/UploadDialog";
import PaySupplierBalanceListModule from "@/views/develop/paySupplierBalance/module/PaySupplierBalanceListModule.vue";

export default {
  name: "GoodsSupplierList",
  components: {
    PaySupplierBalanceListModule,
    GoodsSupplierForm,
    UploadDialog
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 供应商信息管理表格数据
      dataList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        name: null,
        taxNo: null,
        addr: null,
        tel: null,
        bankName: null,
        bankNo: null,
        goodsInfo: null,
        info: null,
        status: null,
      },
      url: {
        list: '/goodsSupplier/goodsSupplier/list',
        remove: '/goodsSupplier/goodsSupplier/',
        export: '/goodsSupplier/goodsSupplier/export',
      },
      tableMaxHeight: window.innerHeight - 320,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询供应商信息管理列表 */
    getList() {
      this.loading = true;
      getAction(this.url.list, this.queryParams).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.form.handleAdd();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$refs.form.handleUpdate(row);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      deleteAction(this.url.remove, ids).then(response => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(this.url.export, {
        ...this.queryParams
      }, `goodsSupplier_${new Date().getTime()}.xlsx`)
    },

    handleFileSuccess(response, file, fileList) {
      this.$refs.uploadDialog.open = false;
      this.$refs.uploadDialog.isUploading = false;
      if (response.data.code == "200") {
        this.$alert("导入数据：" + response.data.num + "条！更新数据：" + response.data.numupdate + "条！" + response.data.errorText, "导入结果", {dangerouslyUseHTMLString: true});
      } else {
        this.$alert("导入数据：" + response.data.num + "条！更新数据：" + response.data.numupdate + "条！" + response.data.errorText, "导入结果", {dangerouslyUseHTMLString: true});
      }
      this.getList();
    },
    showUploadDialog() {
      this.$refs.uploadDialog.title = "信息导入";
      this.$refs.uploadDialog.tmplName = "供应商信息模板.xlsx";
      this.$refs.uploadDialog.fileName = "供应商信息.xlsx";
      this.$refs.uploadDialog.uploadUrl = "/goodsSupplier/goodsSupplier/importData";
      this.$refs.uploadDialog.show();
    },

    handleBalanceList(row){
      let supplierId = row.id;
      this.$refs.balanceListModule.show(supplierId);
    }




  }
};
</script>
